import axios from 'axios'
import { baseURL } from '../config' 

function getUserInfo(callback = function(){}){
    axios({
      method: 'get',
      url: baseURL + '/account/accounts',
      headers: {
        'Authorization': localStorage.getItem("token"),
      }
    }).then(res=>{
      sessionStorage.setItem("username",res.data.data.userid);
      sessionStorage.setItem("lastname",res.data.data.lastname);
      sessionStorage.setItem("email",res.data.data.email);
      sessionStorage.setItem("city",res.data.data.city);
      sessionStorage.setItem("phone",res.data.data.phone);
      sessionStorage.setItem("country",res.data.data.country);
      sessionStorage.setItem("addr1",res.data.data.addr1);
      sessionStorage.setItem("addr2",res.data.data.addr2);
      callback();
    }).catch(error=>{
      // token过期
      localStorage.removeItem("token");
      router.push("/login");
    })
}

export default getUserInfo
  